package org.hum.scaffold.serialize;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;

import org.junit.Test;

import com.alibaba.com.caucho.hessian.io.Hessian2Input;
import com.alibaba.com.caucho.hessian.io.Hessian2Output;

public class HessianTest {

	@Test
	public void test1() throws Exception {
		Student stu = new Student();
        stu.setName("huming");
        stu.setHobby("coding");

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        Hessian2Output output = new Hessian2Output(os);
        output.writeObject(stu);
        output.close();
        
        System.out.println(Arrays.toString(os.toByteArray()));
	}

	@Test
	public void test2() throws Exception {
        byte[] bytes = new byte[] { 67, 48, 34, 111, 114, 103, 46, 104, 117, 109, 46, 115, 99, 97, 102, 102, 111, 108, 100, 46, 115, 101, 114, 105, 97, 108, 105, 122, 101, 46, 83, 116, 117, 100, 101, 110, 116, -110, 5, 104, 111, 98, 98, 121, 4, 110, 97, 109, 101, 96, 6, 99, 111, 100, 105, 110, 103, 6, 104, 117, 109, 105, 110, 103 };
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        Hessian2Input input = new Hessian2Input(bis);
        Student student = (Student) input.readObject();
        System.out.println(student);
	}
}
